﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PepsiCo.Business;
using System.Configuration;

namespace PepsiCo.UI
{
    public class BaseMaster : System.Web.UI.MasterPage
    {
        #region Properties
        private PepsiCoDBDataContext db = new PepsiCoDBDataContext(LocalSetting.ConnectionString);
        public PepsiCoDBDataContext DB
        {
            get { return db; }
        }
        public pepsi_User CurUser
        {
            get
            {
                if (Session[_SESSION.USER_NAME] == null) return null;
                return (pepsi_User)Session[_SESSION.USER_NAME];
            }
            set
            {
                if (Session[_SESSION.USER_NAME] == null)
                    Session.Add(_SESSION.USER_NAME, value);
                else Session[_SESSION.USER_NAME] = value;
            }
        }
        public string AccessDeniedURL
        {
            get { return ConfigurationManager.AppSettings["AccessDeniedURL"]; }
        }
        public string DefaultURL
        {
            get { return ConfigurationManager.AppSettings["DefaultURL"]; }
        }
        public string ChangePasswordURL
        {
            get { return ConfigurationManager.AppSettings["ChangePasswordURL"]; }
        }
        public string LoginURL
        {
            get { return ConfigurationManager.AppSettings["LoginURL"]; }
        }
        public string ReturnURL
        {
            get
            {
                string returnURL = (string)Session[_SESSION.RETURN_URL];
                if (returnURL == null || returnURL == AccessDeniedURL || returnURL == LoginURL) return DefaultURL;
                return returnURL;
            }
            set
            {
                if (Session[_SESSION.RETURN_URL] == null)
                    Session.Add(_SESSION.RETURN_URL, value);
                else
                    Session[_SESSION.RETURN_URL] = value;
            }
        }
        #endregion
        
        protected void RedirectToPage(string urlPage)
        {
            Response.Redirect(urlPage);
        }
    }
}